import 'dart:async';
import 'dart:math';
import 'dart:ui' as ui;
import 'package:flutter/animation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'circle_beisaier_anima_learing.dart';

class LoadingCircleChangeMainWidget extends StatefulWidget {
  ///1--题型，2-所有题目
  int selectTab = 1;

  @override
  _LoadingCircleChangeMainWidgetState createState() =>
      _LoadingCircleChangeMainWidgetState();
}

class _LoadingCircleChangeMainWidgetState
    extends State<LoadingCircleChangeMainWidget> {
  //题型
  var topicNum = 10;

  //题型下的题目
  var topicSubNum = 8;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Center(
        child: Container(
          width: 340,
          height: 400,
          color: Color(0xFFFFFFFF),
          child: widget.selectTab == 1
              ? ListView.builder(
                  shrinkWrap: true,
                  itemBuilder: (BuildContext context, int index) {
                    return _buildTitleList(context, index);
                  },
                  itemCount: topicNum,
                )
              : _buildGridItem(40),
        ),
      ),
    );
  }

  ///建立题型，题目布局
  Widget _buildTitleList(BuildContext context, int index) {
    topicSubNum = 8;
    if (index == 0) {
      topicSubNum = 10;
    }
    if (index == 1) {
      topicSubNum = 1;
    }
    if (index == 3) {
      topicSubNum = 4;
    }
    print("index$index");
    return Column(
      children: [
        Container(
            height: 40,
            width: double.infinity,
            alignment: Alignment.centerLeft,
            padding: EdgeInsets.only(left: 20),
            color: Color(0xFFFAFAFA),
            child: Text("【客观题+填空题】",
                style: TextStyle(fontSize: 16, color: Color(0xFF262626)))),
        _buildGridItem(topicSubNum,topicIndex: index)
      ],
    );
  }

  ///建立题目布局,topicIndex是题型的列表
  Widget _buildGridItem(int itemCount,{int? topicIndex}) {
    return GridView.builder(
      shrinkWrap: true,
      // physics: NeverScrollableScrollPhysics(),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 4, mainAxisSpacing: 0, childAspectRatio: 0.82),
      itemBuilder: (BuildContext context, int index) {
        return _buildSubGridItem(context, index,topicIndex: topicIndex);
      },
      itemCount: itemCount,
    );
  }

  ///建立题目布局,topicIndex是题型的列表，index对应的是某个题
  Widget _buildSubGridItem(BuildContext context, int index,{int? topicIndex}) {

    return Container(
      alignment: Alignment.center,
      child: InkWell(
        child: LoadingCircleChangeWidget(
          waveRatio: 1,
          index: index,
        ),
        onTap: () {
          print("topicIndex:$topicIndex----index：$index");
        },
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
